package com.example.pet.controller;

import com.hj.pet.api.FriendsRelService;
import com.hj.pet.model.FriendsRel;
import com.hj.pet.model.ReturnT;
import com.hj.pet.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.hj.pet.constant.Code.SUCCESS;

@RestController
@CrossOrigin
@RequestMapping("internal/FR")
public class FriendsRelController {
    @Autowired
    FriendsRelService friendsRelService;

    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> save(@RequestBody FriendsRel friendsRel){
        friendsRelService.save(friendsRel);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "updateByUserId",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> updateByUserId(@RequestBody FriendsRel friendsRel){
        friendsRelService.updateByUserId(friendsRel);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "findRelsByUser1",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findRelsByUser1(@RequestParam String user_1) {
        List<FriendsRel> friendsRel=friendsRelService.findRelsByUser1(user_1);
        return new ReturnT<>(SUCCESS,friendsRel);
    }

    @RequestMapping(value = "findRelsByUser2",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findRelsByUser2(@RequestParam String user_2) {
        List<FriendsRel> friendsRels=friendsRelService.findRelsByUser2(user_2);
        return new ReturnT<>(SUCCESS,friendsRels);
    }

    @RequestMapping(value = "delRelByUser",method = RequestMethod.DELETE)
    @ResponseBody
    public ReturnT<?> delRelByUser(@RequestParam String user_1,@RequestParam String user_2) {
        friendsRelService.delFriendRel(user_1, user_2);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "findRels",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findRels(@RequestBody FriendsRel friendsRel){
        friendsRelService.findRels(friendsRel);
        return new ReturnT<>(SUCCESS,friendsRel);
    }

    @RequestMapping(value = "addFriendRequest", method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> addFriendRequest(@RequestBody FriendsRel friendRel) {
        return friendsRelService.addFriendRequest(friendRel);
    }

    @RequestMapping(value = "getDealingRels",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> getDealingRels(@RequestParam String user1){
        List<FriendsRel> friendsRels=friendsRelService.getDealingRels(user1);
        return new ReturnT<>(SUCCESS,friendsRels);
    }

    @RequestMapping(value = "getDealingRels2",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> getDealingRels(@RequestParam String user1,@RequestParam Integer status){
        List<FriendsRel> friendsRels=friendsRelService.getDealingRels(user1,status);
        return new ReturnT<>(SUCCESS,friendsRels);
    }

    @RequestMapping(value = "dealFriendRel",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> dealFriendRel(@RequestBody FriendsRel friendsRel){
        friendsRelService.dealFriendRel(friendsRel);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "getAllFriends",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> getAllFriends(@RequestParam String user1){
        List<UserInfo> userInfos=friendsRelService.getAllFriends(user1);
        return new ReturnT<>(SUCCESS,userInfos);
    }
}
